<?php
namespace app\zbj\controller;
use think\Request;
use think\Db;
//营销管理
class Index  extends  Base{

// 用户列表页面
    public function index(Request $request)
    {

       return view('index/index');
    }

    public function showindex()
    {

        return view('index/index');
    }

    public function welcome()
    {
        return view('index/welcome');
    }


    // 出入金统计日期页
    public function crsum()
    {
        $get['start']=isset($get['start'])?$get['start']:date('Y-m-d',strtotime('monday last week'));
        $get['end']=isset($get['end'])?$get['end']:date('Y-m-d');
        $get['name']=isset($get['name'])?trim($get['name']):'';
        $get['p']=isset($get['p'])?$get['p']:config('paginate.list_rows');
        return view('transaction/cjrj/showsum',['get'=>$get]);
    }

    public function crsummary(Request $request)
    {
        $get=$request->get();
//        dump($get);die;
        $get['start']=isset($get['start'])?$get['start']:date('Y-m-d',strtotime('monday last week'));
        $get['end']=isset($get['end'])?$get['end']:date('Y-m-d',strtotime("friday last week"));
        $get['name']=isset($get['name'])?trim($get['name']):'';

        $jystart=str_replace('-','',$get['start']);
//        $jyend=date('Y-m-d',strtotime($get['end'].'+1 day'));
        $jyend=str_replace('-','',$get['end']);
        $jystart=date('Y-m-d H:i:s',strtotime($jystart)-3600*8);
        $jyend=date('Y-m-d H:i:s',strtotime($jyend)+3600*16);

        $list=Db::name('cashlog')
            ->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->field('a.*,b.name')
            ->where('b.refereecode',0)
            ->where('type','in','5,6')
            ->where('b.name','like','%'.$get['name'].'%')
            ->where('time','between',[$jystart,$jyend])
            ->paginate(15,false,['query'=>$get]);


        $page=$list->render();
        $list=$list->items();

        $tj['rj']=Db::name('cashlog')
            ->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->field('a.*,b.name')
            ->where('b.refereecode',0)
            ->where('type','5')
            ->where('b.name','like','%'.$get['name'].'%')
            ->where('time','between',[$jystart,$jyend])
            ->sum('price');
        $tj['cj']=Db::name('cashlog')
            ->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->field('a.*,b.name')
            ->where('b.refereecode',0)
            ->where('type','6')
            ->where('b.name','like','%'.$get['name'].'%')
            ->where('time','between',[$jystart,$jyend])
            ->sum('price');

        return view('transaction/cjrj/showsummary',['list'=>$list,'page'=>$page,'get'=>$get,'tj'=>$tj]);
    }



}
